<?php
namespace app\home\controller;

use think\Controller;
use think\cache\driver\Redis;

class Index extends Controller{
    public function index(){
        $number = input('number');

        $info = db('activity_goods')->field('goods_id')->order('id desc')->limit($number)->select();

        return ['code'=>200,'msg'=>'请求成功','data'=>$info];
    }

    public function redis_test(){
        $redis = new Redis();
        $data = db('activity_goods')->field('goods_id,yjsx_id,sxzh_id')->order('id desc')->select();

        $redis->set("activity_list",$data);

        $res = $redis->get("activity_list");

        return ['code'=>200,'msg'=>'请求成功','data'=>$res];
    }

    public function test(){
        $total_price    = 120;
        $first_pay      = 20;
        $stages         = 3;
        $stages_amount  = $total_price-$first_pay;

        $each_amount    = number_format($stages_amount/$stages,2,'.','');
        if($each_amount*$stages != $stages_amount){
            $each_amount    = number_format($stages_amount/$stages,2,'.','');;
            $stages_amount2 = $each_amount*$stages;

            $first_pay      = $first_pay+($stages_amount-$stages_amount2);
            $stages_amount  = $stages_amount2;
        }

        var_dump($first_pay,$stages_amount);exit;
    }
}
